package com.easy.auth.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.easy.auth.domain.Role;
import com.easy.auth.domain.UploadFile;
import com.easy.auth.service.UploadService;
import com.easy.base.service.impl.EManagerImpl;
import com.easy.base.service.impl.ESession;
import com.easy.common.jdbc.PageInfo;
import com.easy.common.web.PagedList;

 

/**
 * Created with IntelliJ IDEA.
 * User: Van
 * Date: 13-12-14
 * Time: 下午2:18
 * To change this template use File | Settings | File Templates.
 */
@Service 
public class UploadServiceImpl extends EManagerImpl<UploadFile> implements UploadService {
	
	@Override
	public PagedList<UploadFile> getAllUploadFilesLike(UploadFile uploadFile, PageInfo pageInfo) {
		return super.findAllLike(uploadFile, pageInfo);
	}
	@Override
	public PagedList<UploadFile> getAllUploadFiles() {
		UploadFile uploadFile=new UploadFile();
		 PageInfo pageInfo =new PageInfo();
		 pageInfo.setSort("orders");
		 pageInfo.setOrder("ASC");
		 pageInfo.setRows(999);
		return super.findAllLike(uploadFile, pageInfo);
	}
	
	@Override
	public PagedList<UploadFile> getUploadFilesByType(String filetype) {
		UploadFile uploadFile=new UploadFile();
		uploadFile.setFiletype(filetype);
		 PageInfo pageInfo =new PageInfo();
		 pageInfo.setSort("orders");
		 pageInfo.setOrder("ASC");
		 pageInfo.setRows(999);
		return super.findAllLike(uploadFile, pageInfo);
	}
	@Override
	public PagedList<UploadFile> getUploadFilesByType(String fileType,String cartype) {
		UploadFile uploadFile=new UploadFile();
		uploadFile.setFiletype(fileType);
		uploadFile.setCartype(cartype);
		 PageInfo pageInfo =new PageInfo();
		 pageInfo.setSort("orders");
		 pageInfo.setOrder("ASC");
		 pageInfo.setRows(999);
		return super.findAllLike(uploadFile, pageInfo);
	}

	@Override
	public int saveUploadFile(UploadFile uploadFile) {
		return super.saveOrEdit(uploadFile);
	}

	@Override
	public UploadFile findUploadFileById(UploadFile uploadFile) {
		return super.findByOid(uploadFile);
	}

	@Override
	public int removeUploadFiles(String[] oids) {
		List<UploadFile> uploadFileList = new ArrayList<UploadFile>();
		for (String oid : oids) {
			UploadFile uploadFile = new UploadFile();
			uploadFile.setOid(oid);
			uploadFileList.add(uploadFile);
		}
		return super.removeAll(uploadFileList);
	}
	@Override
	public int saveOrEditUploadFile(UploadFile uploadFile) {
		return super.saveOrEdit(uploadFile);
	}

	@Override
	public PagedList<UploadFile> findUploadFiles(UploadFile uploadFile, PageInfo pageInfo) {
		return super.findByDynamicFilterCondition(uploadFile, pageInfo);
	}



	@Override
	public int removeUploadFile(List<UploadFile> iconlist) {
		return super.removeAll(iconlist);
	}

	@Override
	public UploadFile findUploadFileByOid(UploadFile uploadFile) {
		return super.find(uploadFile);
	}
	
	@Override
	public List<UploadFile> findUploadFile() {
		UploadFile state = new UploadFile();
		List<UploadFile> array=super.findList(state);
//		for (int i = 0; i < array.size(); i++) {//sunxiaolong
//			
//			 String icon=array.get(i).getOname();
//			 icon="icon-"+icon;
//			 icon=icon.replaceAll(".png","");
//			 array.get(i).setOname(icon);
//		}
		  return array;
	}
	@Override
	public PagedList<UploadFile> findUploadFileList(UploadFile uploadFile,
			PageInfo pageInfo) {
		
		PagedList<UploadFile> result = super.findListByDynamicFilterCondition(
				uploadFile, pageInfo);
		
		return result;
	}
	@Override
	public int saveAllUploadFile(List<UploadFile> uploadFileList) {
		int count = 0;
		if (uploadFileList != null) {
			for (UploadFile form : uploadFileList) {
				count += saveUploadFile(form);
			}
		}
		return count;
	}
}
